package com.olah.ws.controller;

import com.olah.common.entity.dto.UtilResponse;
import com.olah.common.entity.po.msg.system.SystemMsg;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.olah.ws.service.SystemMsgService;

import javax.annotation.Resource;
import java.util.List;

/**
 * System Message Controller
 */
@RestController
@RequestMapping("/ws/system")
public class SystemMsgController {

    @Resource
    private SystemMsgService service;

    /**
     * 获取用户的系统消息
     * @param id 用户 id
     * @param unreadOnly 是否只查询未阅读的
     * @param count 读取多少条数据
     */
    @GetMapping("/readAll")
    public UtilResponse<List<SystemMsg>> readAll(
        @RequestParam(value = "id") int id,
        @RequestParam(value = "unreadOnly", required = false) boolean unreadOnly,
        @RequestParam(value = "count", required = false) Integer count
    ) {
        return UtilResponse.success(service.readSystemMsg(id, unreadOnly, count));
    }

    /**
     * 执行系统消息的已阅读
     * @param msgId 消息 id
     */
    @GetMapping("/readed")
    public UtilResponse<Boolean> readed(@RequestParam("id") int msgId) {
        service.doRead(msgId);
        return UtilResponse.success(true);
    }

}
